#ifndef __INTERFACE_ADS1115_H__
#define __INTERFACE_ADS1115_H__

#include "Driver_I2C2.h"
#include "Common_Debug.h"

// ADS1115的从机地址+读/写---->这里我们在硬件上把ADDR引脚接到GND
#define SLAVE_ADDRESS 0x48
#define SLAVE_ADDRESS_WRITE SLAVE_ADDRESS << 1
#define SLAVE_ADDRESS_READ  (SLAVE_ADDRESS << 1) + 1

// ADS1115的转换寄存器地址
#define CONVERSION_REGISTER_ADDRESS 0x00
// ADS1115的配置寄存器地址
#define CONFIG_REGISTER_ADDRESS 0x01


//将配置寄存器的每一位进行宏定义，方便后续置0或1
#define CONFIG_OS 0x8000
#define CONFIG_MUX 0x7000
#define CONFIG_MUX_0 0x1000
#define CONFIG_MUX_1 0x2000
#define CONFIG_MUX_2 0x4000
#define CONFIG_PGA 0x0E00
#define CONFIG_PGA_0 0x0200
#define CONFIG_PGA_1 0x0400
#define CONFIG_PGA_2 0x0800
#define CONFIG_MODE 0x0100
#define CONFIG_DR 0x00E0
#define CONFIG_DR_0 0x0020
#define CONFIG_DR_1 0x0040
#define CONFIG_DR_2 0x0080
#define CONFIG_COMP_MODE 0x0010
#define CONFIG_COMP_POL 0x0008
#define CONFIG_COMP_LAT 0x0004
#define CONFIG_COMP_QUE 0x0003
#define CONFIG_COMP_QUE_0 0x0001
#define CONFIG_COMP_QUE_1 0x0002

//配置寄存器默认的值
#define CONFIG_DEFAULT_VALUE 0x8583


/**
 * @brief 初始化外部ADC模块
 *
 */
void Interface_ADS1115_Init(void);

/**
 * @brief 读取外置ADC的数据，并转化为电压值
 *
 * @return double 电压值
 */
double Interface_ADS1115_GetV(void);

#endif /* __INTERFACE_ADS1115_H__ */
